package splug.cjk;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

public class CarPoolTab2CommentWrite extends Thread {

	private InputStream is;
	private OutputStream os;
	private ArrayList<Content> content;
	private int number;
	private String id;
	private String comment;
	
	public CarPoolTab2CommentWrite(InputStream is, OutputStream os, int number,
			String id, String comment) {
		this.is = is;
		this.os = os;
		this.number = number;
		this.id = id;
		this.comment = comment;
	}
	
	public void run(){
		try {
			Class.forName("com.mysql.jdbc.Driver");
			Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/carpool?useUnicode=true&characterEncoding=euckr","root","apmsetup");
			Statement stmt = conn.createStatement();
			
			String query = "INSERT INTO `carpool`.`carpooltab2comment` (`number` ,`comment` ,`id`) " +
					"VALUES ('" + number + "','" + comment + "','" + id + "');";
			
			stmt.execute("SET CHARACTER SET euckr");
			stmt.execute("set names euckr");

			stmt.executeUpdate(query);
			
			System.out.println("BBSCarPoolTab2 Comment Write Complete!");
			
			OutputStreamWriter osw = new OutputStreamWriter(os);
			osw.write('1');
			osw.flush();
			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}	
	}
}
